using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;
using Csla;

namespace Active.Core
{
    /// <summary>
    /// The read only agent infomation.
    /// </summary>
    [Serializable()]
    public class AgentInfo : ReadOnlyBase<AgentInfo>
    {
        #region Business Methods

        // TODO: add your own fields, properties and methods
        private int _id;
        private string _name = string.Empty;
        private int _dealTimes;

        /// <summary>
        /// Gets the id.
        /// </summary>
        /// <value>The id.</value>
        public int Id
        {
            get { return _id; }
        }

        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name
        {
            get { return _name; }
        }

        /// <summary>
        /// Gets the deal times.
        /// </summary>
        /// <value>The deal times.</value>
        public int DealTimes
        {
            get { return _dealTimes; }
        }

        /// <summary>
        /// Override this method to return a unique identifying
        /// vlaue for this object.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// If you can not provide a unique identifying value, it
        /// is best if you can generate such a unique value (even
        /// temporarily). If you can not do that, then return
        /// <see langword="Nothing"/> and then manually override the
        /// <see cref="Equals"/>, <see cref="GetHashCode"/> and
        /// <see cref="ToString"/> methods in your business object.
        /// </remarks>
        protected override object GetIdValue()
        {
            return _id;
        }

        #endregion

        #region Factory Methods

        internal static AgentInfo GetAgentInfo(SafeDataReader dr)
        {
            return new AgentInfo(dr);
        }

        private AgentInfo()
        { /* require use of factory methods */ }

        private AgentInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }

        #endregion

        #region Data Access

        private void Fetch(SafeDataReader dr)
        {
            _id = dr.GetInt32("Id");
            _name = dr.GetString("Name");
            _dealTimes = dr.GetInt32("DealTimes");
        }

        #endregion
    }
}
